package com.healthcloud.service.impl;

import com.healthcloud.constants.UserConsts;
import com.healthcloud.entity.Patient;
import com.healthcloud.entity.PpPatientBaseEntity;
import com.healthcloud.service.PpPatientBaseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.healthcloud.dao.DocPpApplicationDao;
import com.healthcloud.entity.DocPpApplicationEntity;
import com.healthcloud.service.DocPpApplicationService;
import com.healthcloud.utils.PageParam;


@Service("docPpApplicationService")
public class DocPpApplicationServiceImpl implements DocPpApplicationService {
    @Autowired
    private DocPpApplicationDao docPpApplicationDao;

    @Autowired
    private PpPatientBaseService ppPatientBaseService;

    @Override
    public DocPpApplicationEntity queryObject(Long id) {
        return docPpApplicationDao.queryObject(id);
    }

    @Override
    public List<DocPpApplicationEntity> queryList(DocPpApplicationEntity bean, PageParam pageParam) {
        return docPpApplicationDao.queryList(bean, pageParam);
    }

    @Override
    public int queryTotal(DocPpApplicationEntity bean) {
        return docPpApplicationDao.queryTotal(bean);
    }

    @Override
    public void save(DocPpApplicationEntity docPpApplication) {

        PpPatientBaseEntity patientEntity = docPpApplication.getPatientEntity();
        if (StringUtils.isEmpty(patientEntity.getIdcard())) {
            docPpApplication.setPatientEntity(ppPatientBaseService.queryObject(Integer.valueOf(patientEntity.getId().toString())));
        }

        switch (docPpApplication.getConcern()) {
            case "0":
                docPpApplication.setApplytime(new Date());
                break;
            case "1":
                docPpApplication.setAggretime(new Date());
                break;
            case "2":
                docPpApplication.setCanceltime(new Date());
                break;
        }

        docPpApplicationDao.save(docPpApplication);
    }

    @Override
    public void update(DocPpApplicationEntity docPpApplication) {
        docPpApplicationDao.update(docPpApplication);
    }

    @Override
    public void delete(Long id) {
        docPpApplicationDao.delete(id);
    }

    @Override
    public void deleteBatch(Long[] ids) {
        docPpApplicationDao.deleteBatch(ids);
    }

}
